/*
 * @Author: 471826078@qq.com
 * @Date: 2020-05-18 16:51:09
 * @LastEditors: younghxp
 * @LastEditTime: 2022-05-16 17:26:28
 */

// var uploadUrl = ""  //文件上传url

// 打包时候用
// var url, uploadUrl;
// var host = window.location.host;
// var protocol = document.location.protocol;
// url = uploadUrl = protocol + "//" + host + "/";
// 10.10.12.23:8090
// 平时用
// var url = 'http://10.10.12.29:8090/'; //修改bug服务器地址
var url = 'http://192.168.9.36:7001/' //修改bug服务器地址
var uploadUrl = 'http://192.168.9.36:7001/' //文件上传url

function packageParams(data) {
  return JSON.stringify(data)
}

export default {
  //请求路径
  commonApi: url,
  //文件路径
  uploadUrl: uploadUrl,
  //测试ip1
  // testIp1: 'http://192.168.9.52:7001/nc',
  // //测试ip2
  // testIp2: 'http://192.168.9.180:7001/nc',
  testIp1: '192.168.9.52',
  //测试ip2
  testIp2: '192.168.9.180',
  //测试ip3
  testIp3: '192.168.9.190',
  //测试ip4
  testIp4: '192.168.9.207',
  //测试ip5
  testIp5: 'devel.sunhj.cn',
  //测试ip6
  testIp6: '192.168.9.172',
  //测试ip7
  testIp7: '192.168.9.36',
  //封装请求函数
  install: function (Vue) {
    Vue.prototype.packageParams = (data) => packageParams(data)
  },
  // 手机号、银行卡号等脱敏
  deseHandler: function (str, frontLen, endLen, wildcard) {
    if (!str) {
      return '--'
    } else if (str.length < 9) {
      return str
    } else {
      var len = str.length - frontLen - endLen
      var xing = ''
      for (var i = 0; i < len; i++) {
        xing += wildcard
      }
      return (
        str.substring(0, frontLen) + xing + str.substring(str.length - endLen)
      )
    }
  },
  //格林威志时间格式化 ie/chorme
  GMTFormat(time, flag) {
    var date = time.substr(0, 10) //年月日
    var hours = time.substring(11, 13)
    var minutes = time.substring(14, 16)
    var seconds = time.substring(17, 19)
    var timeFlag = date + ' ' + hours + ':' + minutes + ':' + seconds
    timeFlag = timeFlag.replace(/-/g, '/')
    timeFlag = new Date(timeFlag)
    timeFlag = new Date(timeFlag.getTime() + 8 * 3600 * 1000)
    if (flag) {
      timeFlag =
        timeFlag.getFullYear() +
        '-' +
        (timeFlag.getMonth() + 1 < 10
          ? '0' + (timeFlag.getMonth() + 1)
          : timeFlag.getMonth() + 1) +
        '-' +
        (timeFlag.getDate() < 10
          ? '0' + timeFlag.getDate()
          : timeFlag.getDate())
    } else {
      timeFlag =
        timeFlag.getFullYear() +
        '-' +
        (timeFlag.getMonth() + 1 < 10
          ? '0' + (timeFlag.getMonth() + 1)
          : timeFlag.getMonth() + 1) +
        '-' +
        (timeFlag.getDate() < 10
          ? '0' + timeFlag.getDate()
          : timeFlag.getDate()) +
        ' ' +
        (timeFlag.getHours() < 10
          ? '0' + timeFlag.getHours()
          : timeFlag.getHours()) +
        ':' +
        (timeFlag.getMinutes() < 10
          ? '0' + timeFlag.getMinutes()
          : timeFlag.getMinutes()) +
        ':' +
        (timeFlag.getSeconds() < 10
          ? '0' + timeFlag.getSeconds()
          : timeFlag.getSeconds())
    }

    return timeFlag
  },
  //日期，月份小于10 补0
  pad(source) {
    return source < 10 ? '0' + source : source
  },
}
